package com.seeyon.ctp.rest.resources;

import java.util.Date;
import java.util.Map;

import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import org.apache.commons.lang3.time.DateFormatUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.google.common.collect.Maps;
import com.seeyon.apps.kk.manager.restImpl.AttendanceDataImpl;
import com.seeyon.apps.kk.manager.restImpl.DocumentHandoutImpl;
import com.seeyon.ctp.common.AppContext;


/**
 * 开放给数字档案系统使用
 * 
 * @author seeyon
 *
 */
@Path("/shkk/document")
public class DocumentFlow extends BaseResource {

	private static final Log log = LogFactory.getLog(DocumentFlow.class);
	private DocumentHandoutImpl document = null;

	/**
	 * 调用接口自动发起流程
	 * 
	 * @return
	 */
	@SuppressWarnings("deprecation")
	@POST
	@Path("/autoDocumentFlow")
	@Produces({ MediaType.APPLICATION_JSON, MediaType.TEXT_HTML })
	@Consumes({ MediaType.APPLICATION_JSON, MediaType.TEXT_HTML })
	public Response autoDocumentFlow(Map<String, Object> params) {
		log.info("======shkk=====数字档案远程调用：" + params + "\n调用日期："
				+ DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
		Map<String, Object> result = Maps.newHashMap();
		if(!params.isEmpty()){
			long flag =  getInit().autoDocumentFlow(params);
			if (flag != -1L) {
				result.put("message", "流程自动发起！");
				result.put("result", flag);
			} else {
				result.put("message", "流程自动发起错误！"+params);
				result.put("result", flag);
			}
		} else {
			result.put("message", "调用参数错误！"+params);
			result.put("result", "0");
		}
		log.info("=======shkk===========数字档案远程调用结束============="+result);
		return ok(result);
	}
	
	
	@SuppressWarnings("unused")
	private DocumentHandoutImpl getInit(){
		if(document == null)
			document = (DocumentHandoutImpl) AppContext.getBean("documentHandoutImpl");
		return document;
	}
}
